package com.kynnnn.cloud.mybatis_interceptor.controller;

import com.kynnnn.cloud.mybatis_interceptor.entity.Person;
import com.kynnnn.cloud.mybatis_interceptor.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author Zhudiwei
 * @Description TODO
 * @createTime 2021年09月03日
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @PostMapping("/save")
    public Object save(@RequestBody Person person) {
        return personService.save(person);
    }

    @GetMapping("/list")
    public Object findAllPerson() {
        return personService.list();
    }

    @GetMapping("/get")
    public Object get(@RequestParam("id") String id) {
        return personService.getById(id);
    }

    @GetMapping("/save/multi")
    public Object multiSave() {
        Person person = null;
        int size = 10;
        for (int i = 0; i < size; i++) {
            person = new Person()
                    .setIdNumber("11010519678543761" + i)
                    .setName("玐瑭兲繜" + (i + 1))
                    .setPhone("1872876785" + i);
            personService.save(person);
        }
        return true;
    }

}
